<?php if (!defined("_ECRIRE_INC_VERSION")) return; if (class_exists('ProprieteModel')) return;

include_spip('classes/pdk_model'); 
class ProprieteModel extends pdk_Model {   
    
    public function __construct() {
        parent::__construct();
        $this->config_model();
    }
    
    function config_model() {
        // Define main table:
        $this->main_table = 'spip_ecatalogue_proprietes';
        
        // Define primary key:
        $this->primary_key = 'id_propriete';
        
        // Define main table fields:
        $this->main_fields['id_propriete'] = 'id_propriete'; 
        $this->main_fields['id_groupe'] = 'id_groupe';        
        $this->main_fields['titre'] = 'titre';        
        $this->main_fields['type'] = 'type';
        $this->main_fields['soustitre'] = 'soustitre';
        $this->main_fields['texte'] = 'texte';
        // Define validation rules:
         $this->validation->set_rules( 
            array(
                array(
                     'field'   => 'id_propriete',
                     'label'   => 'ID propriete',
                     'rules'   => ''
                ),
                array(
                     'field'   => 'titre',
                     'label'   => _T('ecatalogue:propriete_titre'),
                     'rules'   => 'required'
                ),
                array(
                     'field'   => 'type',
                     'label'   => _T('ecatalogue:propriete_type'),
                     'rules'   => 'required|callback_propriete_type_check'
                ),
            )
         );
         
         $this->validation->set_message('propriete_type_check', 'Поле %s может принимать только значение checkbox, select или radio');                                       
    }
}

// Callback validation function for propriete titre:
    function propriete_type_check($str)
	{
		if ($str != 'checkbox' || $str != 'select' || $str != 'radio')
		{	
			return FALSE;
		}
		else
		{
			return TRUE;
		}
	} 
?>